import QtQuick
import QtQuick.Controls
import Qt.labs.platform

Rectangle {
    id: importLDFileWin
    width: 640
    height: 480
    clip: true
    visible: false
    color: mBackColor

    signal ldFileProcessOver()
    signal actionErrorTips(var tips)

    property color mBackColor: "#34393e"
    property color mTextColor: "#e1e4e8"
    property color mContentColor: "#44484d"

    property var helpContent: qsTr(" \
1. 选择一个ld文件进行参数预览，参数不可修改仅可查看\n \
2. 查看参数后点击导入将ld文件生成灯效 \
")

    Connections {
        target: myHandle

        function onLdFileOpened() {
            ledNum.inputText = myHandle.getMyProperty("lNum")
            ledValidFrameNum.inputText = myHandle.getMyProperty("fValidNum")
        }

        function onLdFileProcessed() {
            progressBar.cpbValue = 1
        }
    }

    CustomHeaderBarClose {
        id: headerBar
        x: 0
        y: 0
        width: parent.width
        height: 34
        chbTitleText: qsTr("ld文件导入预览")
        chbHelpText: helpContent

        onClosePageBtnClicked: {
            parent.visible = false
        }
    }

    Column {
        anchors.top: headerBar.bottom
        anchors.bottom: parent.bottom
        width: parent.width
        spacing: 20
        padding: 20

        CustomBorderTitle {
            id: cbtFrameCut
            width: parent.width - parent.padding * 2
            height: 70
            radius: 10
            cbtTitle: qsTr("文件参数")
            cbtTitleBackColor: mBackColor
            cbtTitleX: 30
            cbtFontSize: 14
            cbtTitleColor: mTextColor
            color: mContentColor

            Row {
                x: 10
                y: 20
                width: parent.width
                height: 30
                spacing: 20

                TitleTextInput {
                    id: ledNum
                    width: 120
                    height: parent.height
                    titleText: qsTr("灯珠数:")
                    titleWidth: 60
                    textColor: mTextColor
                    textSize: 14
                    inputBackColor: mContentColor
                    inputBorderWidth: 1
                    inputBorderColor: "#888888"
                    inputText: "0"
                    inputReadOnly: true
                    inputValidator: RegularExpressionValidator { regularExpression: /[0-9]+/ } // 文本验证器 仅可输入数字
                }

                TitleTextInput {
                    id: ledValidFrameNum
                    width: 120
                    height: parent.height
                    titleText: qsTr("总帧数:")
                    titleWidth: 60
                    textColor: mTextColor
                    textSize: 14
                    inputBackColor: mContentColor
                    inputBorderWidth: 1
                    inputBorderColor: "#888888"
                    inputText: "0"
                    inputReadOnly: true
                    inputValidator: RegularExpressionValidator { regularExpression: /[0-9]+/ } // 文本验证器 仅可输入数字
                }

                AsButton {
                    id: importLDFileBtn
                    width: 60
                    height: parent.height
                    text: qsTr("选择")
                    borderWidth: 1
                    backColor: mContentColor
                    textColor: mTextColor
                    itemRadius: 8
                    font.pixelSize: 14

                    onClicked: {
                        myHandle.importAndOpenLDFile()
                    }
                }

                AsButton {
                    id: processLDFileBtn
                    width: 60
                    height: parent.height
                    text: qsTr("导入")
                    borderWidth: 1
                    backColor: mContentColor
                    textColor: mTextColor
                    itemRadius: 8
                    font.pixelSize: 14

                    onClicked: {
                        progressBar.reset()
                        if(Number(ledNum.inputText) && Number(ledValidFrameNum.inputText)) {
                            progressBar.cpbValue = 0.9
                            myHandle.processLDFile()
                        } else {
                            actionErrorTips(qsTr("请先选择有效文件"))
                        }
                    }
                }
            }
        }
    }

    CustomProgressBar1 {
        id: progressBar
        width: parent.width
        height: 16
        anchors.bottom: parent.bottom
        cpbForeGradient: 100
        cpbBackColor: mContentColor
        cpbTextColor: "#FFFFFF"

        onAnimationOver: {
            ldFileProcessOver()
        }
    }

}
